package com.hzjy.api.controller;

import com.hzjy.api.service.impl.ApiTradeNewsServiceImpl;
import com.hzjy.common.core.domain.AjaxResult;
import com.hzjy.common.utils.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 行业资讯
 * @author SS
 */
@Api("行业资讯")
@RestController
@RequestMapping("/api/tradeNews")
public class ApiTradeNewsController {
    @Autowired
    private ApiTradeNewsServiceImpl apiTradeNewsService;

    @ApiOperation("获取行业资讯-分页")
    @PostMapping("/list")
    public AjaxResult list(@RequestBody PageData pd){
        PageData pageData = new PageData();
        if(pd.isEmpty()){
            pd.put("currentPage",0);
        }else{
            pd.put("currentPage",(Integer.parseInt(pd.get("currentPage").toString())-1)*Integer.parseInt(pd.get("pageSize").toString()));
        }
        List<PageData> tradeNewsList=apiTradeNewsService.getTreadeNewsList(pd);
        List<PageData> tradeNewsListAllNum=apiTradeNewsService.getTreadeNewsList(pageData);
        Integer currentPage=apiTradeNewsService.getTreadeNewsNum();
        int total = tradeNewsListAllNum.size();
        Map map=new HashMap();
        map.put("tradeNewsList",tradeNewsList);
        map.put("currentPage",currentPage);
        map.put("total",total);
        return AjaxResult.success(200,"成功",map);
    }

    @ApiOperation("行业资讯-详情")
    @PostMapping("/byId")
    public AjaxResult byId(@RequestBody PageData pd){
        PageData tradeNews=apiTradeNewsService.getTradeNewsById(Long.parseLong(pd.get("trade_news_id").toString()));
        Map map=new HashMap();
        map.put("tradeNews",tradeNews);
        return AjaxResult.success(200,"成功",map);
    }
}
